package com.servlet;

import com.entity.Staff;
import com.dao.StaffDao;
import com.dao.Impl.StaffDaoImpl;
import com.util.MyUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/loginServlet")
public class LoginPdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String user = request.getParameter("user");
        String pass = request.getParameter("pass");
        Staff staff = new StaffDaoImpl().findStaffIdPass(Integer.valueOf(user), pass);
        if(staff!=null) {
            request.getSession().setAttribute("staff",staff);
            MyUtil.jsonWriter(response,"1");
        }else{
            MyUtil.jsonWriter(response,"0");
        }
    }
}
